<?php
/**
 * WebmasterCity V3
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category	WebmasterCity V3
 * @package	 Bootstrap
 * @copyright   (c) Copyright 2009-2010 by wmcity.nl
 *
 * $Id: Doctrine.php 214 2009-06-18 21:24:03Z luckyluke56 $
 */

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initRoutes()
	{
		$this -> bootstrap('frontController');
		$this -> frontController -> setRequest(new Zend_Controller_Request_Http())
			-> setBaseUrl();

		// Read URL ini
		$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/urls.ini', APPLICATION_ENV);
		$router = new Zend_Controller_Router_Rewrite();
		//$router -> addConfig($config, 'routes');

		//$this -> frontController -> setRouter($router);
	}

	protected function _initSession()
	{
		Zend_Session::start();

		return new Zend_Session_Namespace('auth');
	}

	protected function _initUser()
	{
		$this -> bootstrap('session');
		$this -> bootstrap('doctrine');
		$this -> bootstrap('layout');

		$layout = $this -> getResource('layout');

		$session = $this -> getResource('session');

		if(!$session -> logged_in)
		{
			$user = new stdClass();
			$user -> username = "Gast";
			$user -> id = -1;
			$user -> user_style = $layout -> getLayout();
		}
		else
		{
			$table = Doctrine::getTable('User');
			$user = $table -> getUser($session -> user_id);
		}

		return $user;
	}

	protected function _initView()
	{
		$this -> bootstrap('layout');
		$this -> bootstrap('user');

		$layout = $this -> getResource('layout');
		$view = $layout -> getView();

		// Get user
		$user = $this -> getResource('user');

		if(!empty($user -> user_style))
		{
			$layout -> setLayout($user -> user_style);
		}

		$view -> doctype('XHTML1_STRICT');
		$view -> headMeta() -> appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
		$view -> headTitle() -> setSeparator(' / ');
		$view -> headTitle('Webmaster City');
		$view -> user = $user;

		$baseUrl = $this -> frontController -> getBaseUrl();
		$view -> headLink() -> appendStylesheet($baseUrl.'/layouts/'.$layout -> getLayout().'/css/style.css');
	}
}

